package com.android.equipment.base;

import static com.android.equipment.utils.ToastUtil.showToast;

import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.usb.UsbDevice;
import android.os.Handler;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.android.equipment.ObjectBox;
import com.android.equipment.net.OkGoConfig;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.Utils;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper;
//import cn.wch.uartlib.WCHUARTManager;
//import cn.wch.uartlib.WCHUARTManager;
//import cn.wch.uartlib.callback.IUsbStateChange;
import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.onAdaptListener;

/**
 * BaseApplication
 */
public class BaseApplication extends Application {

    public static BaseApplication mBaseApp;
    /**
     * 主线程ID
     */
    public static int mMainThreadId = -1;

    /**
     * 主线程Handler
     */
    public static Handler mMainThreadHandler;


    @Override
    public void onCreate() {
        super.onCreate();
        if (mBaseApp == null) {
            mBaseApp = this;
        }

        //自己的工具类
        Utils.init(this);
        OkGoConfig.initOkGo();
        initAutoSize();
        BGASwipeBackHelper.init(this, null);
        ObjectBox.init(this);
        mMainThreadId = android.os.Process.myTid();
        mMainThreadHandler = new Handler();
        //WCHUARTManager.getInstance().init(this);


    }




    public static BaseApplication getApplication() {
        return mBaseApp;
    }

    static void initAutoSize() {
        //设置app字体不随系统字体改变
        AutoSizeConfig.getInstance()
                .setExcludeFontScale(true)
                .setOnAdaptListener(new onAdaptListener() {
                    @Override
                    public void onAdaptBefore(Object target, Activity activity) {
                        //使用以下代码, 可以解决横竖屏切换时的屏幕适配问题
                        AutoSizeConfig.getInstance().setScreenWidth(ScreenUtils.getScreenWidth());
                        AutoSizeConfig.getInstance().setScreenHeight(ScreenUtils.getScreenHeight());
                    }

                    @Override
                    public void onAdaptAfter(Object target, Activity activity) {
                    }
                })
                .getExternalAdaptManager();
    }


    /**
     * 获取上下文 Context
     */
    public static Context getContext() {
        return mBaseApp.getApplicationContext();
    }



    /**
     * 获取主线程ID
     */
    public static int getMainThreadId() {
        return mMainThreadId;
    }



    /**
     * 获取主线程的handler
     */
    public static Handler getMainThreadHandler() {
        return mMainThreadHandler;
    }



}
